<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 86177
  Date: 2023/6/27
  Time: 19:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .head{
            width: 80%;
            height: 10%;
            background-color: #b6b7c3;
            color: #0f0f0f;
            text-align: center;
            margin: 0 auto;
            font-size: 80%;
        }
        .bd{
            width:80% ;
            text-align: center;
            margin: 0 auto;
        }
    </style>
    <%!
        String url=null;
        String username=null;
        String password=null;
        Connection conn=null;
        Statement std=null;
        ResultSet resultSet=null;
        String sql=null;
    %>
    <%
    try {
      Class.forName("com.mysql.jdbc.Driver");
      url="jdbc:mysql://localhost:3306/library";
      username="root";
      password="20030607";
      sql="select * from announcement";
      conn= DriverManager.getConnection(url,username,password);
      std=conn.createStatement();
      resultSet= std.executeQuery(sql);
    }catch (Exception e){
      out.print(e);
      e.printStackTrace();
    }
  %><!--连接数据库的基本操作-->
</head>
<body bgcolor="#f5f5dc">
<div class="head"><h1>公告</h1></div>
<div class="bd">
    <table border="1px" align="center" bgcolor="#f5f5dc">
        <tr>
            <th>标题</th>
            <th>内容</th>
            <th>发布时间</th>
        </tr>
        <%try {
            while (resultSet.next()) {
                out.print("<tr>");
                out.print("<td>" + resultSet.getString("announcement_title") + "</td>");
                out.print("<td>" + resultSet.getString("content") + "</td>");
                out.print("<td>" + resultSet.getTimestamp("time") + "</td>" + "</tr>");
            }
            resultSet.close();
            std.close();
            conn.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        %>
    </table>
</div>
</body>
</html>
